package com.webzavod.model;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.*;

/**
 * Created by IntelliJ IDEA.
 * User: v.tsapaev
 * Date: 26.05.12
 * Time: 19:52
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "authorities", schema = "public")
public class Authority {

    private static Logger LOG = LoggerFactory.getLogger(Authority.class);

    @Id
    @Column(name = "authority_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer authorityId;

    @Column(nullable = false, unique = true)
    private String authority;

//    @Column(name = "user_id")
//    private Long userId;

    public Authority(){}

    public Authority(String authority){
        this();
        this.authority = authority;
    }

    public String getAuthority() {
        return authority;
    }

    public void setAuthority(String authority) {
        this.authority = authority;
    }

    public Integer getAuthorityId() {
        return authorityId;
    }

    public void setAuthorityId(Integer authorityId) {
        this.authorityId = authorityId;
    }
//
//    public Long getUserId() {
//        return userId;
//    }
//
//    public void setUserId(Long userId) {
//        this.userId = userId;
//    }

    @Override
    public boolean equals(Object o) {
        LOG.info("equals authority = " + o);
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Authority authority1 = (Authority) o;
        LOG.info("equals authority = " + authority1);
        if (authority != null ? !authority.equals(authority1.authority) : authority1.authority != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = authority != null ? authority.hashCode() : 0;
        return result;
    }

    @Override
    public String toString() {
        return "Authority{" +
                "authorityId='" + authorityId + '\'' +
                ", authority='" + authority + '\'' +
//                ", userId=" + userId +
                '}';
    }
}
